//
//  CLHomeViewController.m
//  Class_IOS
//
//  Created by peter on 14-8-20.
//  Copyright (c) 2014年 qiuyang. All rights reserved.
//

#import "CLHomeViewController.h"
#import "CLTabBarController.h"

#import "CLJobViewController.h"
#import "CLFindViewController.h"
#import "CLUserInfoViewController.h"
#import "CLNetworkStatus.h"

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

@interface CLHomeViewController ()

@end

@implementation CLHomeViewController

-(id)init
{
    self = [super init];
    if (self) {
    }
    return  self;
}

- (void)ceshi
{
    NSString *str = [[NSString alloc] init];
    AFNetworkReachabilityStatus status = [[CLNetworkStatus shareNetworkStatus] currentStatus];
    switch (status) {
        case 0:
            str = @"NONET";
            break;
        case 1:
            str = @"WWAN";
            break;
        case 2:
            str = @"2G";
            break;
        case 3:
            str = @"3G";
            break;
        case 4:
            str = @"WIFI";
            break;
            
        default:
            break;
    }
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 200)];
    label.text = str;
    [self.view addSubview:label];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)right
{
    NSLog(@"right");
    [[super self].drawerController startDrawerController:QYDrawerRightType animated:YES completion:NULL];
    
    [MobClick event:@"rightDrawer"];
    
    [self.navigationItem.titleView resignFirstResponder];
    
}

- (void)loadBackgroundView
{
    self.view.backgroundColor = [UIColor yellowColor];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.image = [UIImage imageNamed:@"me.png"];
    [self.view addSubview:imageView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Right", @"") style:UIBarButtonItemStyleBordered target:self action:@selector(right)];
    
    self.navigationItem.titleView = [self addSearchBarToNavigationBar];
    
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture)];
    [self.view addGestureRecognizer:tapGestureRecognizer];
    
    self.view.backgroundColor = [UIColor yellowColor];
    
    //[self loadBackgroundView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)tapGesture
{
    [self.navigationItem.titleView resignFirstResponder];
}

- (UISearchBar *)addSearchBarToNavigationBar
{
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 250, 40)];
    searchBar.delegate = self;
    searchBar.backgroundColor = [UIColor clearColor];
    [searchBar setPlaceholder:@"搜索"];
    
    return searchBar;
}

#pragma  mark add controller
- (UIViewController *)tabBarController
{
    CLTabBarController *clTabBarController = [[CLTabBarController alloc] init];
#warning mark tabbar国际化
    NSMutableArray *clTabBarArray = [[NSMutableArray alloc] init];
    NSArray *titleArray = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil];
    NSArray *vcArray = [self viewController];
    for (int index = 0; index < 4; ++index) {
        UIViewController *currentVC = [vcArray objectAtIndex:index];
        //[currentVC setTitle:[titleArray objectAtIndex:index]];
        currentVC.tabBarItem.title = @"1";
        currentVC.tabBarItem.image = [UIImage imageNamed:@"tabbar.png"];
        
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:currentVC];
        [navController setTitle:[titleArray objectAtIndex:index]];
        
        
        [clTabBarArray addObject:navController];
    }
    
    [clTabBarController setViewControllers:clTabBarArray];
    return  clTabBarController;
}

- (NSArray *)viewController
{
    NSArray *viewArray = [NSArray arrayWithObjects:[[CLHomeViewController alloc] init],
                          [[CLJobViewController alloc] init],
                          [[CLFindViewController alloc] init],
                          [[CLUserInfoViewController alloc] init],nil];
    return viewArray;
}


@end
